package com.jike.noobmoney.mvp.view.fragment;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.TopMouthAdapter;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.GoldPromotionEntity;
import com.jike.noobmoney.entity.MoneyEntity;
import com.jike.noobmoney.helper.ImageLoader;
import com.jike.noobmoney.mvp.presenter.TaskPresenter;
import com.jike.noobmoney.mvp.presenter.UserPresenter;
import com.jike.noobmoney.mvp.view.activity.ChongZhiActivity;
import com.jike.noobmoney.mvp.view.activity.LianXiUsActivity;
import com.jike.noobmoney.mvp.view.activity.MainActivity;
import com.jike.noobmoney.mvp.view.activity.MyInfoActivity;
import com.jike.noobmoney.mvp.view.activity.MyPushActivity;
import com.jike.noobmoney.mvp.view.activity.MyTaskActivity;
import com.jike.noobmoney.mvp.view.activity.RankActivity;
import com.jike.noobmoney.mvp.view.activity.RankMouthActivity;
import com.jike.noobmoney.mvp.view.activity.RankMouthTwoActivity;
import com.jike.noobmoney.mvp.view.activity.SettingActivity;
import com.jike.noobmoney.mvp.view.activity.ShouZhiActivity;
import com.jike.noobmoney.mvp.view.activity.TiXianActivity;
import com.jike.noobmoney.mvp.view.activity.TiXianCenterActivity;
import com.jike.noobmoney.mvp.view.activity.VideoTwoActivity;
import com.jike.noobmoney.mvp.view.widget.CommonDialog;
import com.jike.noobmoney.mvp.view.widget.TiXianDialog;
import com.jike.noobmoney.net.IView;
import com.jike.noobmoney.rxbus.RxBus;
import com.jike.noobmoney.rxbus.RxBusRoute;
import com.jike.noobmoney.rxbus.RxEvent;
import com.jike.noobmoney.util.SPUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by kekex on 2018/8/21.
 * Home
 */
public class RankFragment extends BaseFragment implements IView {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_back)
    ImageView back;

    @BindView(R.id.tv_up_month)
    TextView tv_up_month;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private TaskPresenter taskPresenter;
    private TopMouthAdapter topInviteAdapter;
    private List<GoldPromotionEntity.InviteweekrankBean> mData = new ArrayList<>();
    @Override
    protected int layoutResID() {
        return R.layout.fragment_mouth_rank;
    }

    @Override
    public void onResume() {
        super.onResume();
    }



    @Override
    protected void initData() {
        tvTitle.setText("月度排行榜");
        back.setVisibility(View.GONE);
        taskPresenter = new TaskPresenter(this);

        topInviteAdapter = new TopMouthAdapter(context);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(topInviteAdapter);
        tv_up_month.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), RankMouthTwoActivity.class);
                context.startActivity(intent);
            }
        });
        getData();
    }

//    @OnClick({R.id.iv_back
//    })
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.iv_back:
//                //退出登录
//
//                break;
//        }
//    }


    /**
     * 获取数据
     */
    private void getData() {
        showProgressDialog();
        taskPresenter.getInviteList("1", "0", ConstantValue.RequestKey.top_invite);
    }



    @Override
    protected boolean isRegistRxBus() {
        return true;
    }

    /**
     * 注册订阅事件
     */
    protected void receiveEvent(RxEvent rxEvent) {
        switch (rxEvent.busName) {
            case RxBusRoute.REFRESH_USER_INFO:

                break;
        }
    }



    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        dismissProgressDialog();
        if (ConstantValue.RequestKey.top_invite.equals(actionType)) {
            List<GoldPromotionEntity.InviteweekrankBean> goldpromotionlist = (List<GoldPromotionEntity.InviteweekrankBean>) data;
            if (goldpromotionlist != null && goldpromotionlist.size() > 0) {
                mData.clear();
                mData.addAll(goldpromotionlist);
            }
            topInviteAdapter.refresh(mData);
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        dismissProgressDialog();
    }
}
